package com.senmo.fragment;

import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.senmo.activity.user.LoginActivity;
import com.senmo.base.BaseFragment;
import com.senmo.manager.AccountManager;
import com.senmo.senmo.R;

import lx.af.utils.ActivityUtils.ActivityResultCallback;
import lx.af.utils.ActivityUtils.ImageCropper;
import lx.af.utils.ViewInject.ViewInject;

/**
 * author: lx
 * date: 16-1-5
 */
public class MainTabPersonal extends BaseFragment implements View.OnClickListener {

    @ViewInject(id = R.id.fragment_personal_avatar, click = "onClick")
    private ImageView mAvatarView;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_tab_personal, null);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        view.findViewById(R.id.fragment_personal_pref_edit).setOnClickListener(this);
        view.findViewById(R.id.fragment_personal_pref_settings).setOnClickListener(this);
        view.findViewById(R.id.fragment_personal_pref_about).setOnClickListener(this);
        view.findViewById(R.id.fragment_personal_btn_logout).setOnClickListener(this);
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.fragment_personal_avatar: {
                ImageCropper.of(this).asSquare().maxSize(300, 300).start(new ActivityResultCallback<Uri>() {
                    @Override
                    public void onActivityResult(int resultCode, @NonNull Uri result) {
                        ImageLoader.getInstance().displayImage(result.toString(), mAvatarView);
                    }
                });
                break;
            }
            case R.id.fragment_personal_btn_logout: {
                AccountManager.getInstance().logout();
                startActivity(LoginActivity.class);
                getActivity().finish();
                break;
            }
            case R.id.fragment_personal_pref_edit: {

                break;
            }
            case R.id.fragment_personal_pref_settings: {

                break;
            }
            case R.id.fragment_personal_pref_about: {

                break;
            }
        }
    }
}
